package main.java.com.lee.threadlocal;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/12/16
 */
public class PractiseDemo {

	public void serviceMethod() {
		sleepSecond(1);
		SpeedLog.logPoint("service");
		daoMethod();
		rpcMethod();
	}

	public void daoMethod() {
		sleepSecond(2);
		SpeedLog.logPoint("dao");
	}

	public void rpcMethod() {
		sleepSecond(3);
		SpeedLog.logPoint("rpc");
	}

	private static void sleepSecond(int time) {
		try {
			Thread.sleep(time * 1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

	}

	public static void main(String[] args) {
		PractiseDemo practiseDemo = new PractiseDemo();
		ExecutorService executorService = Executors.newSingleThreadExecutor();
		executorService.submit(() -> {
			SpeedLog.beginSpeedLog();
			practiseDemo.serviceMethod();
			SpeedLog.print();
			SpeedLog.endSpeedLog();
		});
		executorService.shutdown();
	}
}
